<?php namespace Admin\Controller; 

use Admin\AuthController as Controller;
use Admin\Model\User;
class AdminController extends Controller{
	protected $db;
	public function __init(){
		$this->db=new User;
	}
    //动作
	public function index(){
		$data = Db::table('user u')
		->join('user_role ur','u.id','=','ur.user_id')
		->join('role r','ur.role_id','=','r.id')
		->where('r.type',1)
		->get();
		View::with('data',$data);
		View::make();
	}

	public function create()
	{
		if(IS_POST)
		{
			if($this->db->store())
			{
				$this->success('添加成功','index');
			}
			else
			{
				$this->error($this->db->getError());
			}
		}
		else{
			$role = Db::table('role')->where('type',1)->get();
			View::with('role',$role);
			View::make();
		}
	}

	public function edit()
	{
		if(IS_POST)
		{
			if($this->db->update())
			{
				$this->success('修改成功','index');
			}
			else
			{
				$this->error($this->db->getError());
			}
		}
		else
		{
			//获取栏目数据
			$user= new \Admin\Model\User;
			$us=$user->getAll();

			View::with('us',$us);
			View::make();
		}
	}
}














